package cn.zhentao.controller;

import cn.zhentao.dao.UserDao;
import cn.zhentao.pojo.Address;
import cn.zhentao.pojo.User;
import cn.zhentao.service.UserService;
import cn.zhentao.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService userService;
    @PostMapping("login")
    //登录的方法 前端传实体类
    public User login(@RequestBody User user){
      return userService.findByUserNameAndPassWordUser(user.getUsername(), user.getPassword());
    };
    @PostMapping("address")
    //添加地址的方法
    public int addAddress(@RequestBody Address address) {
        return userService.addAddress(address);
    }
    @GetMapping("findAllAddress")
        //根据用户表id查询所有
    public List<Address> findAllAddress(int userId){
        return userService.findAllAddress(userId);
    };
    @PostMapping("regist")
    //注册的方法
    public int regist(@RequestBody User user){
        return userService.insertUser(user);
    }
    @GetMapping("findAllByRoleId")
        //查询所有用户信息
    public List<UserVo> findAllByRoleId(@RequestParam int userId){
        return userService.findAllByRoleId(userId);
    };
    @PutMapping("updateAddress")
    //修改地址信息
    public int updateAddress(@RequestBody Address address){
        return userService.updateAddress(address);
    }
    @GetMapping("findAllAddressByUserId")
    public List<Address> findAllAddressByUserId() {
        return userService.findAllAddressByUserId();
    }
}
